//
//  FileManager+Extension.swift
//  ANOASTORE
//
//  Created by hudan on 2025/5/19.
//  Copyright © 2025 zwb. All rights reserved.
//

import Foundation

extension FileManager {
    /// 重命名沙盒中的文件
    /// - Parameters:
    ///   - originalURL: 原文件的URL
    ///   - newFileName: 新文件名（带扩展名）
    /// - Returns: 新文件的URL，如果失败返回nil
    func renameFile(at originalURL: URL, to newFileName: String) -> URL? {
        let directory = originalURL.deletingLastPathComponent()
        let newURL = directory.appendingPathComponent(newFileName)
        do {
            try moveItem(at: originalURL, to: newURL)
            return newURL
        } catch {
            print("重命名失败：\(error)")
            return nil
        }
    }
}
